<template>
  <div class="tag-box">
    <el-tag
     @close="handelClose(item,index)"
     @click="changeMenu(item)"
      v-for="(item,index) in tags"
      :key="item.path"
      :closable="item.name !== 'home'"
      :effect=" $route.name === item.name ? 'dark' : 'plain'"
    >
    {{item.label}}
    </el-tag>
  </div>
</template>
<script>
import { mapState,mapMutations } from "vuex"
export default ({
    data(){
        return{

        }
    },
    computed:{
        ...mapState({
            tags:state =>state.tab.tabList
        })
    },
    methods:{
        ...mapMutations(['closeTag']),
        //跳转功能
        changeMenu(item){
            this.$router.push({name:item.name})
        },
        // 删除功能
        handelClose(item,index){
            this.closeTag(item)
            const length=this.tags.length
            // 删除之后的跳转逻辑
            if(item.name !== this.$route.name){
                return
            }
            if(index === length){
                this.$router.push({
                    name:this.tags[index-1].name
                })
            }else{
                this.$router.push({
                    name:this.tags[index].name
                })
            }
        }
    }
})
</script>
<style scoped>

</style>